package org.aeon.client.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.client.context.GlobalContext;
import org.aeon.client.view.components.menuPanel.PopupPrompt;
import org.aeon.message.response.ResponseMessage;

import java.util.concurrent.CountDownLatch;

/**
 * @author: MissingAeon
 * @date: 2024/1/31 12:46
 * @description:
 */
@Slf4j
@ChannelHandler.Sharable
public class ResponseHandler extends SimpleChannelInboundHandler<ResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ResponseMessage msg) throws Exception {
        final CountDownLatch downLatch = GlobalContext.getContext().getWaits().remove(msg.getResponseID());
        if (downLatch != null) {
            downLatch.countDown();
        }
        log.debug("服务器消息：" + msg.getReason());
    }
}
